/*
 * @Author: lusx 
 * @Date: 2020-05-13 14:11:05 
 * @Last Modified by: lusx
 * @Last Modified time: 2020-05-26 15:00:46
 */
import { observable, action, computed, toJS } from 'mobx';
import { ListViewPage, SearchPage } from 'weaver-mobile-page';
import { getAttentionTaskList, getMyTaskList, getProFeedBack, getProjectList, getProjectCount, getProListResult } from '../../apis/govern';
// 页面只有一个列表适用 
export default class {
    @observable list = {};
    @observable route = '';
    @observable searchid = 'search';
    @computed get searchPage() {
        //console.log(this.route)
        return new SearchPage.Store({ route: this.route, id: this.searchid });
    }
    @observable loading = false;
    // 状态统计
    @observable pies = [];
    @observable title = '';

    @action
    init = (params) => {
        this.loading = true;
        let { route, quicktype,pathname, ...others = {} } = params;
        this.route = route;
        this.list = new ListViewPage.Store({ route, id: 'list' });
        const apis = {
            'attention': getAttentionTaskList,
            'expiring': getMyTaskList,
            'view-feedback': getProFeedBack,
            'ongoing': getProjectList,
            'will_overtime': getProjectList,
            'new_urgent': getProjectList,
            'overtime': getProjectList,
            'new_feedback': getProjectList,
            'new_instruct': getProjectList,
            'statistics': getProjectCount,
            'status': getProjectCount,
            'statusList': getProListResult
        }[quicktype];
        let isgetProjectList = quicktype === 'ongoing' || quicktype === 'will_overtime' || quicktype === 'new_urgent' || quicktype === 'overtime' || quicktype === 'new_feedback' || quicktype === 'new_instruct';
        // 点击6个穿透项对应的列表入参
        others = isgetProjectList ? { ...others, ...{ flag: 'getlist', type: quicktype } } : others;
        //console.log("oterhs",others,pathname)
        if (isgetProjectList){
            others.tasktype = pathname.substring(pathname.lastIndexOf("/") + 1) == '1' ? '1' : '0';
            this.searchid = "search/"+ others.tasktype ;
        } else{
            this.searchid = "search";
        }
        if ('view-feedback' === quicktype) {
            others = { dataType: 13 ,...others}
        }
        if ('expiring' === quicktype) {
            others = { mobileRemind: 1 ,...others}
        }
        apis(others).then(result => {
            if (result.status === '1') {
                if (apis.name === 'getProjectCount') {
                    const { pies, title } = result;
                    this.list.getData({ 'dataKey': result.sessionkey, 'pageSize': 6 });
                    this.pies = pies[0];
                    this.title = title;
                } else {
                    this.list.getData({ 'dataKey': result.sessionkey });
                }
            }
        })
            .catch((err) => { console.error('error', err) })
            .finally(() => { this.loading = false })
    }
}